import React from 'react';
import { observer, inject } from 'mobx-react';
import renderNoRight from '../../../../utils/renderNoRight'
import TaskViewExcel from '../../taskview/page/excel';
import '../index.less';
import { Icon, Tools,Toast } from 'weaver-mobile';
import classnames from 'classnames';
import { TabPage,RouteLayout } from 'weaver-mobile-page';
const { getLabel } = Tools;
const ButtonGroup = RouteLayout.ButtonGroup;
@inject('edcExcelPageViewStore')
@observer
export default class EdcExcelPage extends React.Component {
    componentDidMount() {
        const { edcExcelPageViewStore: store, location: { search } } = this.props;
        if(search){
            let ps = search.substring(1).split("&");
            const params = {};
            for(let i = 0 ; i < ps.length; i++) {
              let p = ps[i].split("=");
              if(p.length > 1)
                params[p[0]] = p[1]
            }
        store.init({ ...params, from: 'view' });
    }
    }
    componentWillReceiveProps(nextProps) {
        if (nextProps !== this.props) {
            const { edcExcelPageViewStore: store, location: {search} } = nextProps;
            if(search){
                let ps = search.substring(1).split("&");
                const params = {};
                for(let i = 0 ; i < ps.length; i++) {
                  let p = ps[i].split("=");
                  if(p.length > 1)
                    params[p[0]] = p[1]
                }
            store.init({ ...params, from: 'view' });
        }
    }
}

switchPcLayout() {
    if (!window.e9mobileConfig) {
        window.e9mobileConfig = {
          orientation: 2, // 0 竖屏 1 横屏 2 跟随
        }
      } 
      if(window.e9mobileConfig.orientation == 0) {
        window.e9mobileConfig.orientation = 2;
      } else {
        window.e9mobileConfig.orientation = 0;
      }
}
    // getButtons = () => {
    //     const { edcExcelPageViewStore: store, location: { query } } = this.props;
    //     const readonly = true;
    //     store.canSubmit = !readonly;
    //     const buttons = readonly ? [
    //     ] : [
    //         <Button  disabled={store.loading} onClick={store.save} type="primary">{getLabel(30986,'保存')}</Button>,
    //     ];
    //     (readonly && query.modeId )? buttons.push(<Button  disabled={store.loading} onClick={store.toEdit} type="primary">{getLabel('501169', '编辑')}</Button>) : "";
    //     // 需要有完全控制权限的才有
    //     buttons.push(<Button  disabled={store.loading} onClick={store.deleteData} type="primary">{getLabel(502286, '删除')}</Button>);
    //     buttons.push(<Button disabled={store.loading} onClick={store.exportExcel} type="primary">{getLabel(502294,'导出')}</Button>)
    //     readonly ? "" : buttons.push(<Button disabled={store.loading} onClick={(bool) => store.setVisible(bool)} type="primary">{getLabel('502835','导入数据')}</Button>);
    //     return buttons;
    // }
    render() {
        const { edcExcelPageViewStore: store, location: { query } } = this.props;
        store.readonly = true;
        if (store.loadingPage) {
            Toast.loading('Loading...')
         }
        if (store.isRight !== undefined && !store.isRight) {
            return renderNoRight();
        }

        // let tabBtns = [];
        // tabBtns.push([
        //     <div className="wf-req-switch-pc" onClick={this.switchPcLayout.bind(this)}>
        //         <Icon type={1 == "2" ? "sault" : "pc"} />
        //     </div>
        // ]);

        const menu = [];
        // 手机端下载有些问题，先不支持
        // menu.push({
        //     key:'7',
        //     content:getLabel(502294,'导出'),
        //     title:getLabel(502294,'导出'),
        //     key:'daochu',
        //     flex: 12,
        //     onClick: store.exportExcel,
        //     disabled:store.loading
        //   })
        return (
            <div className="edc-excel-page">
                <div className="wf-req-top">
                    {/* <TabPage
                        //tabs={tabs}
                        //btns={tabBtns} span={2} 
                        //tabProps={tabProps} 
                        //popover popoverProps={popoverProps}
                    /> */}
                </div>
                <div className={classnames("edc-task-view-content",`${menu && (menu.length > 0) ? ' edc-task-view-content-notall' : 'edc-task-view-content-all'}`)}>
                <TaskViewExcel store={store} readonly={store.readonly}></TaskViewExcel>    
                </div>
            { menu && (menu.length > 0) && <ButtonGroup data={menu} isButton={false} /> }
            </div>
        )
    }
}